package com.orilore.gb.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.orilore.gb.entity.XUser;
import com.orilore.gb.util.Config;

public class XUserDao {
	
	
	public List<XUser> getPageQuery(Connection conn,int begin) throws SQLException{
		
		   List<XUser> list = new ArrayList<XUser>();
		   
		   
		   String sql = "select * from x_users limit ?,?";
		   
		   
		   PreparedStatement  ps = conn.prepareStatement(sql);
		   
		   
		   ps.setInt(1, begin);
		   
		   ps.setInt(2, Config.pageSize);
		   
		   
		   ResultSet  rs = ps.executeQuery();
		   
		   
		   while(rs.next()) {
			   
			   XUser user = new XUser();
			   
			   
			   user.setId(rs.getInt(1));
			   
			   user.setUsername(rs.getString(2));
			   
			   user.setAge(rs.getInt(3));
			   
			   user.setSex(rs.getInt(4));
			   
			   user.setAddress(rs.getString(5));
			   
			   user.setPhone(rs.getString(6));
			   
			   
			   list.add(user);
			   
			   
			   
			   
		   }
		   
		rs.close();
		
		ps.close();
		
		
		   
		   return list;
		
	}
	
	
	public int  queryCount(Connection conn) throws SQLException {
		
		   int result = 0;
		   
		   
		   String sql = "select  count(*) from x_users";
		   
		   
		   PreparedStatement ps = conn.prepareStatement(sql);
		   
		   
		   ResultSet rs = ps.executeQuery();
		   
		   
		   rs.next();
		   
		   result = rs.getInt(1);
		   
		   
		   rs.close();
		   
		   
		   ps.close();
		   
		   
		   
		   
		   
		   
		   return result;
		
		
		
		
		
	}  

}
